package com.clerkq.FlvPlayer
{
	import com.clerkq.FlvPlayer.event.VideoPlayerEvent;
	import com.clerkq.FlvPlayer.ui.TitlePop;
	import com.content.model.LoadedAssets.SkinProxy;
	import com.content.view.Component.Loader.BufferRing;
	import com.library.core.IDisposable;
	import com.library.core.UIObject;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;

	public dynamic class VideoDecorate extends UIObject implements IDisposable
	{
		private var _titlePop:TitlePop;		
		private var _videoHitBtn:Sprite;
		private var _bufferRing:BufferRing;
		
		public function VideoDecorate()
		{
			super();
			addTitle();
			addHitArea();
			addBufferRing();
			
			addListener();
		}
		
		private function addTitle():void{			
			_titlePop = new TitlePop();
			addChild(_titlePop);
			_titlePop.title = "";
			_titlePop.x = 9.5;
			_titlePop.y = 360;
		}
		
		private function addHitArea():void{
			_videoHitBtn = new SkinProxy.VideoPlayer_VideoMask() as Sprite;
			_videoHitBtn.buttonMode = true;
			_videoHitBtn.alpha = 0.01;
			addChild(_videoHitBtn);
			_videoHitBtn.x = 9.5;
			_videoHitBtn.y = 10;
		}
		
		private function addBufferRing():void{
			_bufferRing = new BufferRing();
			addChild(_bufferRing);
			_bufferRing.x = _videoHitBtn.x + _videoHitBtn.width/2;
			_bufferRing.y = _videoHitBtn.y + _videoHitBtn.height/2;
		}
		
		private function addListener():void{
			_videoHitBtn.addEventListener(MouseEvent.ROLL_OVER, onVideoRollOver);
			_videoHitBtn.addEventListener(MouseEvent.ROLL_OUT, onVideoRollOut);
			_videoHitBtn.addEventListener(MouseEvent.CLICK, onVideoClick);
		}
		
		private function removeListener():void{
			_videoHitBtn.removeEventListener(MouseEvent.ROLL_OVER, onVideoRollOver);
			_videoHitBtn.removeEventListener(MouseEvent.ROLL_OUT, onVideoRollOut);
			_videoHitBtn.removeEventListener(MouseEvent.CLICK, onVideoClick);
		}
		
		
		// PUBLIC /////////////////////////////////////
		public function Dispose():void
		{
			removeListener();
			
			_titlePop.Dispose();		
			//_videoHitBtn;
			_bufferRing.Dispose();
			
			removeAllChilds();
		}
		
		public function showBufferRing():void					{			_bufferRing.fadeIn();		}
		public function hideBufferRing():void					{			_bufferRing.fadeOut();		}
		
		// EVENT //////////////////////////////////
		private function onVideoRollOver(evt:MouseEvent):void{
			_titlePop.show();
		}
		
		private function onVideoRollOut(evt:MouseEvent):void{
			_titlePop.hide();
		}
		
		private function onVideoClick(evt:MouseEvent):void{
			dispatchEvent(new Event(VideoPlayerEvent.CLICK_VIDEO));
		}
		
		// GET AND SET ///////////////////////////////////////////////
		public function set title(value:String):void		{		_titlePop.title = value;	}
		
	}
}